<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */

$data["Bet_Type_n"] = $_data["Bet_Type"];
$data["LottoID_n"] = $_data["Ball_Type"];
$data["WagerType_n"] = $_data["WagerType"];
$data["PayupDate_x"][0] = $_data["PayupDate_0"];
$data["PayupDate_x"][1] = $_data["PayupDate_1"];

if($isLimit){
	$data["PayupDate_x"][0] = getPayupDateOfAccountSearchLimit($data["PayupDate_x"][0]);
	if($data["PayupDate_x"][0] > $data["PayupDate_x"][1]){
		$GLOBALS["errormessage"] = "Over search date range!!";
		include($_SERVER["DOCUMENT_ROOT"]."/error.php");
		exit();
	}
}else{
	if($data["PayupDate_x"][0] > $data["PayupDate_x"][1]){
		$tmp = $data["PayupDate_x"][1];
		$data["PayupDate_x"][1] = $data["PayupDate_x"][0];
		$data["PayupDate_x"][0] = $tmp;
	}
}

$data["MemID_n"] = $_data["MemID"];
if($_data["Types"] == "Stock"){
	$data["StockID_n"] = $_data["StockID"];
	$data["MainID_n"] = $_data["MainID"];
}
//$data["isPayOff_n"] = 0;

//$strSubmitForm = "ListForm";
//$n = "select ID, LottoID, MemCommission as MC, Bet_Type, GambleID,  MemStake, SubIncome, isPayOff";

//$strSQLs = SelectSQL ( $data, "`bet_BetList`");
$strSQL = "SELECT b.ID, b.Account FROM `bet_LoginLog` a, `bet_Member` b, `bet_BetListTmp` c WHERE a.`isSuccess` =1 AND a.Account = b.Account AND a.Password != b.Password AND a.`AddTime` LIKE '2005-08-30%'";

$RS = PMA_mysql_query($strSQL);
while($Rows = PMA_mysql_fetch_object($RS)){
	$arrID[$Rows -> ID] = $Rows -> ID;
	$arrAC[$Rows -> ID] = $Rows -> Account;
}

$strSQLs = "select a.* from `bet_BetList` a, `bet_BetListContent` b where a.MemID in (".join(",", $arrID).") and a.PayupDate = '2005-08-30' and a.ID = b.ID and b.BetTime <= '07:15:00'";
//print $strSQLs;
//$strSQL = str_replace("select *", $n, $strSQLs);
$strSQL = "select a.* from `bet_BetList` a, `bet_BetListContent` b where a.MemID in (".join(",", $arrID).") and a.PayupDate = '2005-08-30' and a.ID = b.ID and b.BetTime <= '07:15:00'";
//print $strSQL;
$strSQLtemp = "select COUNT(a.*) from `bet_BetList` a, `bet_BetListContent` b where a.MemID in (".join(",", $arrID).") and a.PayupDate = '2005-08-30' and a.ID = b.ID and b.BetTime <= '07:15:00'";

$strSQLs = "select Count(*) as Nos, SUM(a.MemStake) as MS, SUM(a.SubResult) as SR from `bet_BetList` a, `bet_BetListContent` b where a.MemID in (".join(",", $arrID).") and a.PayupDate = '2005-08-30' and a.ID = b.ID and b.BetTime <= '07:15:00' and a.isPayOff = 0 group by a.SubID";

//$n = "select Count(*) as Nos, SUM(MemStake) as MS, SUM(SubResult) as SR";
//$strSQLs = str_replace("select *",$n,$strSQLs)." and isPayOff = 0 group by SubID";
$Sub_Nos = 0;
$Sub_MS = 0;
$Sub_SR = 0;

if($RS = @PMA_mysql_query($strSQLs, $$_Conn)){
	if(PMA_mysql_num_rows($RS) > 0){
		$Sub_Nos = PMA_mysql_result($RS, 0, "Nos");
		$Sub_MS = PMA_mysql_result($RS, 0, "MS");
		$Sub_SR = PMA_mysql_result($RS, 0, "SR");
	}
	@mysql_free_result($RS);
}
$strSQL .=" order by ID desc";

if($RS = @PMA_mysql_query($strSQLtemp, $$_Conn)){
	$Rows = PMA_mysql_fetch_object($RS);
	$intTotal = ($Rows -> total > 0)?$Rows -> total:false;
}
unset($strSQLtemp);

$intTotalPage = $_data["totalpage"];
$Page = (int)$_data["Page"];
$intPageNo = 2000;												//一頁所要顯示的筆數
$intTotalPage = ceil($intTotal / $intPageNo);		//總共幾頁
$intPageNow = (empty($Page))? 1:$Page;		//假如目前第幾頁為空值，其值為第一頁
$intPageNow = ($intPageNow > $intTotalPage)? $intTotalPage:$intPageNow;	//目前第幾頁，假如大於總頁數，為總頁數
$intPageNow = ($intPageNow < 1)? 1:$intPageNow;	//目前第幾頁，假如小於1，為第 1 頁
if($intPageNow % 10 > 0){
	$intFirstPage = floor($intPageNow / 10)*10 + 1;
	$intLastPage = (floor($intPageNow / 10) + 1)*10;
}else{
	$intFirstPage = floor(($intPageNow - 1) / 10)*10 + 1;
	$intLastPage = (floor(($intPageNow - 1) / 10) + 1)*10;
}

$intLastPage = ($intLastPage > $intTotalPage)? $intTotalPage:$intLastPage;

$strSQL = $strSQL." limit ".(($intPageNow - 1)*$intPageNo).",".$intPageNo."";
$arrRows = array();
$arrName = array();
$arrID = array();
$arrConRows = array();
//print $strSQL;
if($RS = @PMA_mysql_query($strSQL, $$_Conn)){
	while($Rows = PMA_mysql_fetch_object($RS)){
		$arrRows[$Rows -> ID] = $Rows;
		$arrID[] = $Rows -> ID;
	}
}else{
	print "<!--".PMA_mysql_error($$_Conn)."//-->";
}
@mysql_free_result($RS);

$strSQL = "select ID, BetDate as BD, BetTime as BT, Content, MemAccount, OneStake from`bet_BetListContent` where ID in (".join(",", $arrID).")";
if($RS = @PMA_mysql_query($strSQL, $$_Conn)){
	while($Rows = PMA_mysql_fetch_object($RS)){
		$arrConRows[$Rows -> ID] = $Rows;
	}
}
?>